home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / DINKDEMO / DC_SCRIB / SCRIBLEM.C < prev    next >
C/C++ Source or Header  |  1992-07-08  |  4KB  |  176 lines

  1. /*
  2.     File:        ScribleMainProgram.c
  3.  
  4.     Written by:    Mark Gross
  5.  
  6.     Copyright:    ⌐ 1992 by Applied Technical Software, all rights reserved.
  7.     Use at your own risk.
  8.  
  9. */
  10.  
  11. //
  12. // this is the model main function modual for the typical DinkClass
  13. // application
  14. //
  15.  
  16. #include "DApplication.h"
  17. #include "DScribbleApp.h"
  18. #include "DScribbleDoc.h"
  19. #include "DinkUtils.h"
  20.  
  21. //
  22. //Core apple event prototypes
  23. //
  24. void DoAEInstallation(void);
  25.  
  26. pascal OSErr HandleQUIT( AppleEvent *theAppleEvent, AppleEvent *reply,
  27.                          long myRefCon);
  28. pascal OSErr HandleOAPP( AppleEvent *theAppleEvent, AppleEvent *reply, 
  29.                          long myRefCon);
  30. pascal OSErr HandlePDOC( AppleEvent *theAppleEvent, AppleEvent *reply,
  31.                          long myRefCon);
  32. pascal OSErr HandleODOC( AppleEvent *theAppleEvent, AppleEvent *reply,
  33.                          long myRefCon);
  34.  
  35.  
  36. main()
  37. {
  38.     DApplication    *theApp;
  39.     
  40.     InitToolBox(5);
  41.  
  42.     if(!System7Available() )
  43.         DebugStr( "\p No System 7!!" );
  44.  
  45.     DEventHandler::gApplication = NULL;// to make sure no messages get sent to gApplication 
  46.                                     // before it is instanicated.  otherwise the Application
  47.                                     // object will be sending install handler message to itself
  48.                                     // befor it is fully instaniated.
  49.     
  50.     theApp = new DScribbleApp;
  51.     
  52.     DEventHandler::gApplication = theApp;
  53.     DEventHandler::gPassItOn = TRUE;
  54.  
  55.     theApp->fCreator = 'MkGR';// use your faverate initials
  56.     theApp->fClipType = 'PICT';
  57.     theApp->fMainFileType = 'PICT';
  58.  
  59.     DoAEInstallation();// the AE-handler procs refrence gApplication 
  60.                         // so I'm initializing the AEvents after I have
  61.                         // a valid gApplication
  62.     
  63.     
  64.     if(theApp->InitApp() )
  65.     {            
  66.         theApp->MakeDDoc(FALSE);
  67.         theApp->EventLoop();
  68.         theApp->CleanUp();
  69.     }
  70.     ExitToShell();    //last good bye kiss
  71. }// the end
  72.  
  73.  
  74.  
  75.  
  76.  
  77. void DoAEInstallation(void)
  78. {
  79.  
  80.     AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments,
  81.                             (EventHandlerProcPtr)HandleODOC, 0, false);
  82.  
  83.     AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,
  84.                             (EventHandlerProcPtr)HandleQUIT, 0, false);
  85.  
  86.     AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments,
  87.                             (EventHandlerProcPtr)HandlePDOC, 0, false);
  88.  
  89.     AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,
  90.                             (EventHandlerProcPtr)HandleOAPP, 0, false);
  91.  
  92. }                            
  93.  
  94.  
  95.  
  96. pascal OSErr HandleQUIT( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  97. {
  98.     OSErr myErr;
  99.     
  100.     myErr = RequiredCheck( theAppleEvent);
  101.     if (myErr) 
  102.         return myErr;
  103.     
  104.     DEventHandler::gApplication->fDone = true;
  105.     return noErr;
  106. }
  107.  
  108.  
  109.  
  110. pascal OSErr HandleOAPP( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  111. {
  112.     OSErr myErr;
  113.  
  114.     myErr = RequiredCheck( theAppleEvent);
  115.     if (myErr) 
  116.         return myErr;
  117.     
  118.     return noErr;
  119. }
  120.  
  121.  
  122.  
  123. pascal OSErr HandlePDOC( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  124. {
  125.     OSErr myErr;
  126.  
  127.     myErr = RequiredCheck( theAppleEvent);
  128.     if (myErr) 
  129.         return myErr;
  130.     
  131.     return errAEEventNotHandled;
  132. }
  133.  
  134.  
  135. pascal OSErr HandleODOC( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  136. {
  137.     OSErr myErr;
  138.     AEDescList  docList;
  139.     FSSpec        myFSS;
  140.     long        i;
  141.     long        itemsInList;
  142.     AEKeyword    theKeyWord;
  143.     DescType    typeCode;
  144.     Size        actualSize;
  145.     WindowPtr    docWindow;
  146.     DDocument* newDoc;
  147.  
  148.     myErr = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
  149.     if ( myErr)
  150.         return(myErr);
  151.  
  152.     myErr = RequiredCheck( theAppleEvent);
  153.     if (myErr) 
  154.         return myErr;
  155.  
  156.  
  157.     myErr = AECountItems(&docList, &itemsInList);
  158.     if (myErr) 
  159.         return myErr;
  160.         
  161.     for (i = 1; ((i <= itemsInList) && (!myErr)); ++i) 
  162.     {
  163.         myErr = AEGetNthPtr( &docList, i, typeFSS, &theKeyWord,    &typeCode, 
  164.             (Ptr)&myFSS, sizeof(FSSpec), &actualSize );
  165.         
  166.         if (myErr) 
  167.             return myErr;
  168.         
  169.         newDoc = new DScribbleDoc;
  170.         if (newDoc)
  171.             newDoc->AEInitDoc(&myFSS); 
  172.     }
  173.     return noErr;
  174. }
  175.  
  176.